﻿using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Flare.Pages.Endpoint
{
    public partial class Index : UserControl, IPubTypicalPage, IDisposable
    {
        public static int? id_department { get; set; }
        public static int? id_room { get; set; }
        public static int? id_nettype { get; set; }


        public string name
        {
            get { return "Сеть"; }
        }

        public Index()
        {
            InitializeComponent();
            //this.Loaded += (s, e) =>
            //{
            //    if (netList.SelectedIndex != -1) CreateFullMenu((int)netList.SelectedValue);
            //};
        }

        public void CreateStartMenu()
        {
            object[] images = new object[] { new FunctionalPanelItems().Insert(typeof(Pages.Endpoint.Create)) };
            glob.kernel.CreateFunctionalPanel(images);
        }

        //void CreateFullMenu(int id)
        //{
        //    object[] images = new object[] { 
        //        new FunctionalPanelItems().Insert(typeof(Pages.Endpoint.Create)), 
        //        new FunctionalPanelItems().Edit(typeof(Pages.Endpoint.Edit), id), 
        //        new FunctionalPanelItems().Delete(typeof(Pages.Endpoint.Delete), id) };
        //    glob.kernel.CreateFunctionalPanel(images);
        //}

        void HandleSearchEvent(object sender, EventArgs e)
        {
            ((ObjectDataProvider)this.Resources["endpointsDataSet"]).MethodParameters[0] = sender;
        }

        private void Department_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["general_roomsDataSet"]).MethodParameters[0] = (int?)Department.SelectedValue;
            ((ObjectDataProvider)this.Resources["endpointsDataSet"]).MethodParameters[1] = (int?)Department.SelectedValue;
        }

        private void Room_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["endpointsDataSet"]).MethodParameters[2] = (int?)Room.SelectedValue;
        }

        private void netType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["endpointsDataSet"]).MethodParameters[3] = (int?)netType.SelectedValue;
        }

        private void ClearFilter_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Department.SelectedIndex = -1;
            netType.SelectedIndex = -1;
        }

        //private void ListBoxItem_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        //{
        //    int ep_id = ((Flare.DB.Entity.EndpointView)((sender as ListBoxItem).Content)).id;
        //    glob.kernel.ShowPage(typeof(Pages.Endpoint.Details), ep_id);
        //    e.Handled = true;
        //}

        //private void ListBoxItem_MouseRightButtonDown(object sender, RoutedEventArgs e)
        //{
        //    if (netList.SelectedIndex != -1 && (sender as ListBoxItem).IsSelected == true)
        //    {
        //        CreateStartMenu();
        //        netList.SelectedItem = null;
        //        e.Handled = true;
        //    }
        //    else
        //    {
        //        CreateFullMenu(((Flare.DB.Entity.EndpointView)((sender as ListBoxItem).Content)).id);
        //    }
        //}

        private void netList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            glob.kernel.ShowPage(typeof(Pages.Endpoint.Details), netList.SelectedValue);
        }

        public void SetSearchString(string _content)
        {
            ((ObjectDataProvider)this.Resources["endpointsDataSet"]).MethodParameters[0] = _content;
        }

        public void Dispose()
        {
            id_department = (int?)Department.SelectedValue;
            id_room = (int?)Room.SelectedValue;
            id_nettype = (int?)netType.SelectedValue;
        }
    }
}
